#include "label.h"
#include <QEvent>
#include <QMouseEvent>
#include <QDebug>
#include <QLabel>

Label::Label(QWidget *parent) : QLabel(parent)
{

}

bool Label::event(QEvent *event)
{
    // 鼠标按下拦截
    if (event->type() == QEvent::MouseButtonPress)
    {
        QMouseEvent* ev = static_cast<QMouseEvent*>(event);
        QString str = QString("event函数按下：x=%1, y=%2").arg(ev->x()).arg(ev->y());
        qDebug() << str;

        return true; // 代表自己处理，不往下分发
    }

    // 其他交给父类
    return QLabel::event(event);
}

void Label::mousePressEvent(QMouseEvent *event)
{
    QString str = QString("鼠标按下：x=%1, y=%2").arg(event->x()).arg(event->y());
    qDebug() << str;
}
